;; The first three lines of this file were inserted by DrScheme. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-beginner-reader.ss" "lang")((modname e1.8) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
(define (square x)
  (* x x ))

(define (cube x)
  (* x x x))

(define (good-enough? tolerance guess x)
  (< (abs (- (cube guess) x)) tolerance))

(define (average x y)
  (/ (+ x y) 2))


;(define (improve guess x)
;  (average guess x))

;(define (improve guess x)
;  (average guess (/ x guess)))

(define (improve guess x)
  (/ (+ (/ x (square guess)) (* 2 guess))
     3))

(define (new-if predicate then-clause else-clause)
  (cond (predicate then-clause)
        (else else-clause)))

(define (cube-iter tolerance guess x)
  (if (good-enough? tolerance guess x)
      guess
      (cube-iter tolerance (improve guess x) 
                 x)))

(define (test x y)
  (= x y))

(define (ogcube tolerance initial-guess x)
  (cube-iter tolerance initial-guess x))
